{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2024-01-21T15:28:16.695805600Z",
     "start_time": "2024-01-21T15:28:14.329431600Z"
    }
   },
   "outputs": [],
   "source": [
    "from transformers import AutoModelForCausalLM, AutoTokenizer\n",
    "from transformers.generation import GenerationConfig"
   ]
  },
  {
   "cell_type": "code",
   "outputs": [],
   "source": [
    "tokenizer = AutoTokenizer.from_pretrained(r\"G:\\llm\\Xunzillm4cc\\Xunzi-Qwen-Chat\", device_map=\"cuda:1\", trust_remote_code=True)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-01-21T15:28:21.068185Z",
     "start_time": "2024-01-21T15:28:20.758426Z"
    }
   },
   "id": "48f88158a2af4977",
   "execution_count": 2
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "data": {
      "text/plain": "Loading checkpoint shards:   0%|          | 0/2 [00:00<?, ?it/s]",
      "application/vnd.jupyter.widget-view+json": {
       "version_major": 2,
       "version_minor": 0,
       "model_id": "a8524717b8464ff0b1c25a1e7de34986"
      }
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "model = AutoModelForCausalLM.from_pretrained(\n",
    "    r\"G:\\llm\\Xunzillm4cc\\Xunzi-Qwen-Chat\",\n",
    "    device_map=\"cuda:1\",\n",
    "    trust_remote_code=True\n",
    ").eval()"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-01-21T15:34:59.298944700Z",
     "start_time": "2024-01-21T15:33:33.333557600Z"
    }
   },
   "id": "c585a42f3a1c41a2",
   "execution_count": 4
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "你好！有什么我可以帮助你的吗？\n"
     ]
    }
   ],
   "source": [
    "response, history = model.chat(tokenizer, \"你好\", history=None)\n",
    "print(response)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-01-21T15:35:38.789527800Z",
     "start_time": "2024-01-21T15:35:36.740735100Z"
    }
   },
   "id": "1c583a6daae6ae75",
   "execution_count": 5
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "有一个年轻人名叫乔布斯，他从小就对电子产品有着浓厚的兴趣，经常捣鼓一些简单的电子设备。在他的高中时期，他就开始学习计算机编程，并开始在自己的宿舍里制造计算机硬件和软件。\n",
      "\n",
      "在大学期间，乔布斯决定辍学并开始创立自己的公司，开发出一系列风靡全球的电子产品，如Macintosh电脑、iPod音乐播放器和iPhone智能手机等。这些产品彻底改变了人们使用计算机和手机的方式。\n",
      "\n",
      "乔布斯在创业的道路上遇到了很多困难和挫折，但他始终坚信自己的梦想，并不断努力创新和改进。最终，他的公司成为全球最有价值的品牌之一，乔布斯也成为了一位享誉全球的商业领袖和技术创新者。\n",
      "\n",
      "这个故事告诉我们，只要拥有梦想、勇气和毅力，就可以在创业的道路上不断前行，最终取得成功。\n"
     ]
    }
   ],
   "source": [
    "response, history = model.chat(tokenizer, \"给我讲一个年轻人奋斗创业最终取得成功的故事。\", history=history)\n",
    "print(response)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-01-21T15:36:04.645366100Z",
     "start_time": "2024-01-21T15:35:52.596211700Z"
    }
   },
   "id": "a7c1ee2a8b167458",
   "execution_count": 6
  },
  {
   "cell_type": "code",
   "outputs": [],
   "source": [],
   "metadata": {
    "collapsed": false
   },
   "id": "b8b4d1a73b03389"
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
